package com.looookme.shaozhuo.mb_study;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.looookme.shaozhuo.activities.Activities;
import com.looookme.shaozhuo.broadcast_service.B_S_List;
import com.looookme.shaozhuo.datasave.DataSaveList;
import com.looookme.shaozhuo.intents.IntentList;
import com.looookme.shaozhuo.keyevent.KeyEventList;
import com.looookme.shaozhuo.msg.MsgList;
import com.looookme.shaozhuo.uiLayout.UiLayout;
import com.looookme.shaozhuo.uicompent.UiUpperCompent;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, BasicAdapter.Callback {
    private ListView listView;
    private List<BasicData> mData;
    private BaseAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initEvent();
    }

    private void initEvent() {
        listView.setOnItemClickListener(this);
    }

    private void initView() {
        listView = (ListView)findViewById(R.id.listView);

        mData = new ArrayList<BasicData>();
        mData.add(new BasicData("", "UiLayout", ""));
        mData.add(new BasicData("", "UiCompent", ""));
        mData.add(new BasicData("", "Notification", ""));
        mData.add(new BasicData("", "Activity", ""));
        mData.add(new BasicData("", "Intent", ""));
        mData.add(new BasicData("", "KeyEvent", ""));
        mData.add(new BasicData("", "BroadCase Service", ""));
        mData.add(new BasicData("", "DataSave", ""));

        mAdapter = new BasicAdapter(this, mData, this);

        listView.setAdapter(mAdapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Toast.makeText(MainActivity.this, mData.get(i).getTextString() + " is Clicked", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void click(View v) {
//        Toast.makeText(MainActivity.this, "CallBack " + mData.get((Integer)v.getTag()).getTextString() + " is Clicked", Toast.LENGTH_SHORT).show();
//        Intent intent = new Intent(MainActivity.this, mData.get((Integer)v.getTag()).getTextString().getClass());
        Intent intent = new Intent();
        switch ((Integer)v.getTag()){
            case 0:
                intent.setClass(MainActivity.this, UiLayout.class);
                break;
            case 1:
                intent.setClass(MainActivity.this, UiUpperCompent.class);
                break;
            case 2:
                intent.setClass(MainActivity.this, MsgList.class);
                break;
            case 3:
                intent.setClass(MainActivity.this, Activities.class);
                break;
            case 4:
                intent.setClass(MainActivity.this, IntentList.class);
                break;
            case 5:
                intent.setClass(MainActivity.this, KeyEventList.class);
                break;
            case 6:
                intent.setClass(MainActivity.this, B_S_List.class);
                break;
            case 7:
                intent.setClass(MainActivity.this, DataSaveList.class);
                break;
        }
        startActivity(intent);
    }
}
